package org.budo.github.api.response;

import java.util.Map;

import org.budo.support.http.client.Response;
import org.budo.support.lang.util.ArrayUtil;
import org.budo.support.servlet.util.QueryStringUtil;

/**
 * @author lmw
 */
public class GithubAccessTokenResponse extends AbstractResponse {
    private static final long serialVersionUID = 8330672149646631454L;

    public GithubAccessTokenResponse() {}

    public GithubAccessTokenResponse(Response response) {
        this.setResponse(response);
    }

    public String getAccessToken() {
        String responseBody = this.getResponse().getBody();

        Map<String, String[]> accessTokenMap = QueryStringUtil.queryStringToMap(responseBody);
        String accessToken = ArrayUtil.first(accessTokenMap.get("access_token"));
        return accessToken;
    }
}